package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.result.ResultCodeEnum;
import lombok.Data;

@Data
public class LeaseException extends RuntimeException {

    //异常状态码
    private Integer code;

    //通过状态码和错误消息创建异常对象
    public LeaseException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    //通过状态枚举对象创建异常对象
    public LeaseException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "LeaseException{" +
                "code=" + code +
                ", message=" + this.getMessage() + '}';
    }


}
